package com.beep.erp.model.home.classify;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.beep.erp.R;
import com.beep.erp.common.bean.BizGoodsListBean;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by jolly on 2018/9/1.
 */

public class ClassifyAdapter extends RecyclerView.Adapter<ClassifyAdapter.StockDetailViewHolder> {

    //当前上下文对象 需要，，必要参数
    private Context mContext;
    private LayoutInflater mLayoutInflater;
    private ArrayList<BizGoodsListBean.BizGoodsBean> mListBeen;
    private OnItemClickLitener mOnItemClickLitener;

    //当前上下文对象mContext必要参数  构造传值
    public ClassifyAdapter(Context mContext, ArrayList<BizGoodsListBean.BizGoodsBean> listBeen) {
        this.mContext = mContext;
        this.mListBeen = listBeen;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    public void setOnItemClickLitener(OnItemClickLitener onItemClickLitener) {
        mOnItemClickLitener = onItemClickLitener;
    }

    //初始化布局的地方 new InviteViewHolder 这个是写在下方的 内部类
    @Override
    public StockDetailViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new StockDetailViewHolder(mLayoutInflater.inflate(R.layout.stock_in_detail_item, parent, false));
    }

    //绑定数据的地方
    @Override
    public void onBindViewHolder(StockDetailViewHolder holder, int position) {
        holder.tvGoodsName.setText(mListBeen.get(position).getGoodsName());
        holder.tvGoodsNo.setText("商品库存:" + mListBeen.get(position).getStockAmount());
        holder.tvExpirationDate.setText("商品规格:" + mListBeen.get(position).getSpecification());
        holder.tvGoodsWaitNo.setText("商品编号:" + mListBeen.get(position).getGoodsCode());
        if (mOnItemClickLitener != null) {
            holder.itemView.setOnClickListener(v -> {
                mOnItemClickLitener.onItemClick(v, position);
            });
        }
    }

    //多少条数据
    @Override
    public int getItemCount() {
        return mListBeen.size();
    }

    //上面提到的内部类 如果要使用@BindView ButterKnife.bind(this, itemView);必须要写
    public class StockDetailViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_goods_name)
        TextView tvGoodsName;
        @BindView(R.id.tv_goods_no)
        TextView tvGoodsNo;
        @BindView(R.id.tv_goods_wait_no)
        TextView tvGoodsWaitNo;
        @BindView(R.id.tv_expirationDate)
        TextView tvExpirationDate;
        @BindView(R.id.iv_point)
        ImageView ivPoint;
        @BindView(R.id.line)
        View line;

        public StockDetailViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface OnItemClickLitener {
        void onItemClick(View view, int position);
    }

}
